package edu.ustb.controller;

import java.awt.print.Printable;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.alibaba.fastjson.JSON;

import edu.ustb.domain.User;
import edu.ustb.mapper.UserXiumiMapper;
import edu.ustb.result.Result;
import edu.ustb.service.UserXiumimaService;
import edu.ustb.service.UserXiumimaServiceImp;

/**
 * Servlet implementation class UserPhoneXiumiController
 */
@WebServlet("/user/xiumima.do")
public class UserXiumimaController extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String newPassword1=request.getParameter("newPassword1");
		String newPassword2=request.getParameter("newPassword2");
		String userPhone=request.getParameter("phone");
		Result result=new Result();
		
		UserXiumimaService xiumima = new UserXiumimaServiceImp();
		
		if(newPassword1.equals(newPassword2)) {
			System.out.println(newPassword1+newPassword2);
			//if(xiumima.Judge(unkonw).equel(1))
			int row = xiumima.changeByPhone(userPhone, newPassword1);
			result.setCode(1);
			result.setMsg("修改成功");
		}else {
			result.setCode(2);
			result.setMsg("修改失败");
		}
			
			
			
		response.getWriter().write(JSON.toJSONString(result));
		System.out.println(JSON.toJSONString(result));
			
			
	
	}

}
